aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/apps/[pubkey]/+page.server.ts
blob: a2cc50e7ead8672dfe759635a87f03181d4dd0d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import getRates from "$lib/rates";
import { auth, fd, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";

export const load = async ({ cookies, params, parent }) => {
	const { pubkey } = params;
	const { user } = await parent();
	const rates = await getRates();
	const rate = rates[user.currency];
	const app = await get(`/app/${pubkey}`, auth(cookies));
	return { app, rate };
};

export const actions = {
	default: async ({ cookies, request }) => {
		try {
			const body = await fd(request);
			await post("/app", body, auth(cookies));
		} catch (e) {
			const { message: error } = e as Error;
			return fail(400, { error });
		}

		redirect(307, "/settings/nostr");
	},
};